#!/bin/sh

OUTPUT1="single_node_output.dat"
OUTPUT2="double_node_output.dat"
PROGNAME="ex03_3"
CNT1=0
CNT2=0

if [ -f $PROGNAME ] 
then

if [ $# -lt 2 ]
then
	echo "Usage ./run.sh <hostname1> <hostname2>"
else
	echo "Given Hostnames" $1 " " $2
	echo "Output will be passed to " $OUTPUT1 " and " $OUTPUT2 
	echo "start run"
	echo "#Start run at " $( date +%T ) > $OUTPUT1
	echo "#Start run at " $( date +%T ) > $OUTPUT2
	while [ $CNT1 -lt 2 ] 
	do	
		CNT1=$(($CNT1 + 1))
		if [ $CNT1 -eq 1 ] 
		then	
			CNT2=1024
			echo "single node execution"
			while [ $CNT2 -lt 1048577 ] 
			do
				echo "SIZE " $CNT2
				echo "mpirun -host" $1 "-np 2 ./"$PROGNAME " >>" $OUTPUT1
				CNT2=$(($CNT2 * 2))
			done	
		else
			CNT2=1024
			echo "dual node execution"
			while [ $CNT2 -lt 1048577 ]
			do 
				echo "SIZE " $CNT2
				echo "mpirun -host" $1","$2 "-np 2 ./"$PROGNAME " >>" $OUTPUT2
				CNT2=$(($CNT2 * 2))
			done
		fi
		
	done
	echo "task full filled. return val " $?
fi 

else
	echo "Can't find file " $PROGNAME ". Execution aborted"
fi
